package com.hgd.evp.common.entity;

import com.hgd.evp.common.utils.StringUtil;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class MergeEntity {
    private Class<?> feignClazz;
    private Method feignMethod;
    private Set<String> feignArgs;

    public MergeEntity() {
    }

    public MergeEntity(Class<?> feignClazz, Method feignMethod, Object args) {
        this.feignArgs = new HashSet<>();

        this.feignClazz = feignClazz;
        this.feignMethod = feignMethod;

        if (args instanceof String) {
            this.feignArgs.addAll(Arrays.asList(StringUtil.split((String) args, ",")));
        } else if (args instanceof Set) {
            for (Object o : (HashSet) args) {
                if (o instanceof String) {
                    this.feignArgs.add((String) o);
                }
            }
        }
    }

    public Class<?> getFeignClazz() {
        return feignClazz;
    }

    public void setFeignClazz(Class<?> clazz) {
        this.feignClazz = clazz;
    }

    public Method getFeignMethod() {
        return feignMethod;
    }

    public void setFeignMethod(Method feignMethod) {
        this.feignMethod = feignMethod;
    }

    public Set<String> getFeignArgs() {
        return feignArgs;
    }

    public void setFeignArgs(Set<String> feignArgs) {
        this.feignArgs = feignArgs;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof MergeEntity) {
            MergeEntity obj1 = (MergeEntity) obj;
            return StringUtil.equals(this.toString(), obj1.toString());
        }

        return false;
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }

    @Override
    public String toString() {
        return "MergeEntity{" +
                "clazz=" + feignClazz +
                ", method='" + feignMethod + '\'' +
                '}';
    }
}
